package com.manli.api.controller;

import java.util.Arrays;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.manli.api.pojo.QueryParams;
import com.manli.api.pojo.QueryParamsUser;
import com.manli.api.pojo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import com.manli.api.base.annotation.Permissions;
import com.manli.api.dto.ViewUser;
import com.manli.api.service.ViewUserService;



/**
 * VIEW
 *
 * @author manli
 * @email 
 * @date 2020-04-28 16:05:32
 */
@Api(value="/viewuser", tags="用户表视图")
@RestController
@RequestMapping("api/viewuser")
public class ViewUserController {
    @Autowired
    private ViewUserService viewUserService;

    /**
     * 列表
     */
    @ApiOperation(value = "VIEW列表",notes = "")
    @PostMapping("/list")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN_PERMISSONS)
    public Result list(@RequestBody QueryParamsUser params, HttpServletRequest request){
        return viewUserService.queryPage(params,request);
    }

    /**
     * 全部数据信息
     */
    @ApiOperation(value = "VIEW全部数据信息",notes = "")
    @PostMapping("/all")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN_PERMISSONS)
    public Result all(){
        return viewUserService.queryAll();
    }

    /**
     * 单条信息
     */
    @ApiOperation(value = "VIEW单条信息",notes = "VIEW单条信息")
    @GetMapping("/info/{userId}")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN_PERMISSONS)
    public Result info(@PathVariable("userId") Integer userId){
        return viewUserService.getById(userId);
    }

    /**
     * 保存
     */
    @ApiOperation(value = "VIEW保存",notes = "VIEW保存")
    @PostMapping("/save")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN_PERMISSONS)
    public Result save(@RequestBody ViewUser viewUser,HttpServletRequest request)throws Exception{
        return viewUserService.save(viewUser,request);
    }

    /**
     * 修改
     */
    @ApiOperation(value = "VIEW修改",notes = "VIEW修改")
    @PostMapping("/update")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN_PERMISSONS)
    public Result update(@RequestBody ViewUser viewUser)throws Exception{
        return viewUserService.updateById(viewUser);
    }

    /**
     * 删除单条数据
     */
    @ApiOperation(value = "VIEW删除",notes = "VIEW删除")
    @ApiImplicitParam(name = "userIds", value = "id",dataType = "int", required = true)
    @DeleteMapping("/delete")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN_PERMISSONS)
    public Result delete(Integer userId){
        return viewUserService.removeById(userId);
    }

    /**
     * 删除多条数据
     */
    @ApiOperation(value = "VIEW删除",notes = "VIEW删除")
    @ApiImplicitParam(name = "userIds", value = "id数组,json字符串",dataType = "id数组,json字符串", required = true)
    @DeleteMapping("/deleteIds")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN_PERMISSONS)
    public Result deleteIds(@RequestBody Integer[] userIds){
        return viewUserService.removeByIds(Arrays.asList(userIds));
    }

}
